package cn.wing.Inventory;

import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;

public class PocketInventoryProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> {
    private final PocketInventory inventory = new PocketInventory();

    @Override
    public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction side) {
        return cap == PocketInventory.CAP
                ? LazyOptional.of(() -> inventory).cast()
                : LazyOptional.empty();
    }

    @Override public CompoundTag serializeNBT() { return inventory.serializeNBT(); }
    @Override public void deserializeNBT(CompoundTag nbt) { inventory.deserializeNBT(nbt); }
}